package james.gan.registry.api;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import james.gan.common.ExtensionLoader;

public class RegistryCenterFacroty {
	
	private static final Map<String, RegistryCenter> registryCenters = new ConcurrentHashMap<>();
	
	static{
		List<RegistryCenter> load = ExtensionLoader.load(RegistryCenter.class, ExtensionLoader.class.getClassLoader());
		load.stream().forEach(r->{
			registryCenters.put(r.getName(), r);
		});
	}

	public static void registe(String name, RegistryCenter registryCenter) {
		registryCenters.putIfAbsent(name, registryCenter);
	}

	public static RegistryCenter get(String name) {
		return registryCenters.get(name);
	}
}
